package com.kfm.servlet.day02;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;

@WebServlet("/params")
public class ParamsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置请求编码
        req.setCharacterEncoding("utf-8");

        String username = req.getParameter("username");
        String[] hobby = req.getParameterValues("hobby");

        Map<String, String[]> parameterMap = req.getParameterMap();

        Set<String> keys = parameterMap.keySet();

        for(String key : keys){
            String[] strings1 = parameterMap.get(key);
            System.out.println(key + " : " + Arrays.toString(strings1));
        }
    }
}
